<template>
    <div class="con">

        <div class="btngroup">
            <span @click="prev()">上一条</span>
            <span class="next" @click="next()">下一条</span>
            <span class="all" @click="all()">全部</span>
        </div>

        <div class="card">
            <img src="../assets/images/notice.png" alt="">
            <div class="text">
                <p class="titlenotice">{{data.title}}</p>
                <p class="time">{{data.createTime}}</p>
                <p class="detail" v-html="data.message"></p>
            </div>

            <div style="height:44px">

            </div>

        </div>
        <div style="height:50px"></div>

    </div>
</template>

<script>
export default {
    name: "notice",
    data() {
        return {
            data: [],
            noticeId: ""
        };
    },
    methods: {
        prev() {
            this.axios
                .get(
                    `${this.siteUrl}/notice/public/detail_next.do?noticeId=${
                        this.noticeId
                    }&step=1`
                )
                .then(response => {          
                    if (response.data.success == 1) {
                        this.data = response.data.data;
                        this.noticeId = response.data.data.noticeId;
                    } else {
                        this.$Message.warning("已是最新公告");
                    }
                })
                .catch(function(error) {
                    console.log(error);
                });
        },
        next() {
            this.axios
                .get(
                    `${this.siteUrl}/notice/public/detail_next.do?noticeId=${
                        this.noticeId
                    }&step=-1`
                )
                .then(response => {
                   
                    if (response.data.success == 1) {
                        this.data = response.data.data;
                        this.noticeId = response.data.data.noticeId;
               
                    } else {
                        this.$Message.warning("已经是最后一条");
                    }
                })
                .catch(function(error) {
                    console.log(error);
                });
        },
        all() {
            this.$router.push({ name: "allNotice" });
        }
    },
    mounted() {
        this.$Message.config({
            top: 200,
            duration: 1
        });

        // 从url获取公告id
        this.noticeId = this.$route.query.noticeId;
        this.axios
            .get(`${this.siteUrl}/notice/public/detail.do?noticeId=${this.noticeId}`)
            .then(response => {
                console.log(response)
                if (response.data.success == 1) {
                
                    this.data = response.data.data;
                    this.noticeId = response.data.data.noticeId;
                }
            })
            .catch(function(error) {
                console.log(error);
            });
    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.con {
    width: 100%;
    min-height: 100vh;
    background: #0b94de;
    overflow: hidden;
}
.btngroup {
    width: 88%;
    margin-left: 6%;
    margin-top: 24px;
}
.btngroup span {
    font-size: 16px;
    color: #ffe2bd;
}
.btngroup .next {
    margin-left: 24px;
}
.btngroup .all {
    float: right;
}
.card {
    width: 92%;
    margin-left: 4%;
    background: #fff;
    margin-top: 20px;
    box-shadow: 0px 2px 6px 0px #0774b0;
    border-radius: 4px;
}
.card img {
    width: 80%;
    margin-left: 10%;
    margin-top: -5px;
}
.card .text {
    width: 80%;
    margin-left: 10%;
    margin-top: -5px;
}
.card .titlenotice {
    font-size: 18px;
    margin-top: 35px;
    line-height: 27px;
}
.card .time {
    color: #999;
    font-size: 12px;
    margin-top: 10px;
    font-weight: 200;

}
.card .detail {
    font-size: 14px;
    margin-top: 15px;
    color: #333333;
    line-height: 21px;
    font-weight: 200;
}

</style>
